import initCycleTLS from "cycletls";
import fs from "fs";
import { CardItem, FollowingData, ImageDetailData, TemplateData } from "../crawlers/canvas-photo/types.js";


//休眠函数: 随机休眠ms-ms2秒
export async function sleep(ms: number, ms2: number) {
  const delay = Math.floor(Math.random() * ms) + ms2;
  await new Promise((resolve) => setTimeout(resolve, delay));
}


fetch("https://www.canva.cn/_ajax/marketplace2/card/masonry?continuationToken=M%40D6kD6S-U7dV8Ow&limit=50&hasPrimaryAction=false", {
  "headers": {
    "accept": "*/*",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "sec-ch-ua": "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-ch-ua-platform-version": "\"10.0.0\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-origin",
    "x-canva-analytics": "AAQAA1dFQgABABowMUpFTU1aTTFCSDRQQUNSTUJUTkYyQ0JLTQ==",
    "x-canva-app": "home",
    "x-canva-authz": "cnvanTFsX5Mdcxxuuc9xeYu-CrHoWh5QfO_Em0TPDvqNJYsNAP2Y2523NN3n-Re0Qefcz6NtkaadTug4_7n6VYBjeO-uDwRqFA9mZlGV-u3le6vo4MVTM96MICI26T_L8yzUmZ89zLCUgWDc2TdaSjbdAbGm3LNEQZ5Jd1v6lMadGgNfZVMPRCB7TXLa_bbLYGrh-5QNMV1Q-sdKrDy3cSNsYq4h9xpjxlsSk06fq-hX6bEu45rsYAssH5g-eGws5xDzca0HAfWy2K0kMXiN01-TSecVZq-wuCRUPikP-h84EPWTYlhEo-Hog5mF6l4bl_LFgDk4DJu2ik8ClzFnfZPd2oyQMFKH1_7LPJqcfQwYepdBujTkleO8oinIN0wLSoro3faqtuKiUG9_T9kbkGcHmd4ob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BJkOCrUJ-ktdEDebWuvx5gLkdW14H7MHraCiz6mitk2Y3aWFAiQNI-9CVwMpyZlP8m-b2BMVfPAgVJB_Ha5QdnLZsrbdorP8836yinbLOPojZnsKs01SYLjp7tpvscDU4taFaPnr__AFKagbDzzfNWnWIwhdskt-ouE5-fM2nZYLQfFy2yo2Q6IQJLOTve1KaVy4LbZpooKfV-YWdS80VCsfl6D-THLAXyhH-tBQZ2Rj7m3y_V4-BRVgynbOL9p8idcThHwMSrL2fFnt_ti2GLgUKipxou_-Xo2rVYIbMgzvJhF12mSxKj5hZy0U_h_RrEcc4hvVZtoGSjPAba1ul5ru5LZ_D4E_R7SDzAg1MS-uWHQ51ThIQOsBEWuVwPicw-5tfdUsJi5drtBl5C8oWgLVAuGQftIrGDejTzAL3bkF9ECtcGGIGt-4Dv8QGVAU3SiWEVc6LVQVxYBm9VETPBj4nJohOAnfvHdoCXBSVQF9c_73BkF-zVRteihyJtIIvAria-4nS0qPZ2uRNqcw23YVmlH-p452Rbrzg8PxtogO2-TjGvch43whW3hXrJWmVRe1otWvcJuL6K21c7tAmIPSs79rLEMi279-S8xVO2M1O06VhNutC1juXUuHSFbWjBfQIMJP1QDFsxb-Ch7cV4DKPvubAMfpAaZXUjrHUcEBgsmRc4IfwDFBggcmYtHy574m6JWUPE3qwXdPMpYFpdgINf0pDgg_d9hdtfPoaQxdK4f9nnag-bX2g7ToaaPtsGsURGFH-QlcoJ7B8A9bLn5WQOovFMgKj_lB-xC6g3vPb1lwtKQuRRdp5Ld3hzv0vMAb8423ad8",
    "x-canva-brand": "BAGEapRcxko",
    "x-canva-build-name": "20241203-21",
    "x-canva-build-sha": "d32ea79",
    "x-canva-locale": "zh-CN",
    "x-canva-request": "findmasonrycards",
    "x-canva-user": "UAGDNGYdGao",
    "cookie": "CDI=5bf62074-c1df-4313-9773-bdad79d82313; sensorsdata2015jssdkchannel=%7B%22prop%22%3A%7B%22_sa_channel_landing_url%22%3A%22%22%7D%7D; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%221931e63da3e6f3-0916c5eaca21928-4c657b58-2073600-1931e63da3f1c47%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_utm_source%22%3A%22bing%22%2C%22%24latest_utm_medium%22%3A%22paid%22%2C%22%24latest_utm_campaign%22%3A%22ACQ-poster-make%22%2C%22%24latest_utm_content%22%3A%22sem%22%2C%22%24latest_utm_term%22%3A%22haibaowangzhan%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTkyOGYyZGJmYjZiOWUtMGQyZTM2YTQzNDg4ZDA4LTRjNjU3YjU4LTkyMTYwMC0xOTI4ZjJkYmZiNzI1OTkifQ%3D%3D%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%7D; CTC=eyJBIjoxNzMxMzgxNjgzMTQ0LCJCIjoxNzMxMzgxNjgzMTQ0LCJEIjpmYWxzZSwiSSI6Wzg0OTM0NzQzOSwyNjM5OTddLCJKIjpbODQ5MzQ3NDMxLDI2Mzk5N119; Hm_lvt_86fb568838e91564c8549e9ef71194cc=1731381683; gdxidpyhxdE=diU%5CziXouCys2USfah0qu0W2eeI%2B%2F%5CWapPzXh%5Cil%5CABVdMNfrU5gdzmDPvWyvLO8ivRfaGya6gjbc1HLd%2FlXhRfkM2R3s%5C%2FsZt%5CIAEBN%2FDLxPQRkg91GDNoe9CzQKQQXa%2FGcq9CANqyixSvHgGGO1BgL5S9Xb4GSE3E6xDAVfjO5x%5CLO%3A1731382584381; CB=BAGEapRcxko; CAU=eyJBIjoiVUFHRE5HWWRHYW8iLCJCIjoiQk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VRteihyJtIIvAria-4nS0qPZ2uRNqcw23YVmlH-p452Rbrzg8PxtogO2-TjGvch43whW3hXrJWmVRe1otWvcJuL6K21c7tAmIPSs79rLEMi279-S8xVO2M1O06VhNutC1juXUuHSFbWjBfQIMJP1QDFsxb-Ch7cV4DKPvubAMfpAaZXUjrHUcEBgsmRc4IfwDFBggcmYtHy574m6JWUPE3qwXdPMpYFpdgINf0pDgg_d9hdtfPoaQxdK4f9nnag-bX2g7ToaaPtsGsURGFH-QlcoJ7B8A9bLn5WQOovFMgKj_lB-xC6g3vPb1lwtKQuRRdp5Ld3hzv0vMAb8423ad8; CID=cnvanD_mfa8ULsQUWnZD4jtdFkxu50pXm3a_0KjxHFPHCjlKUwprbGdOYtcYAbhetqooG84HKwuJIPGwIV-HEutyYbY9dHJ_E0AMLf-gNjitZIfKGjT5Bf3fa5f37; CUI=vj6xLh83RHYgeO9MSK8SXQMSZw-uz_PadpnrsCY4TPzs6ZNktOb2uTCSLTsPE5yxKxWPpw; __cf_bm=cwNhv2O4aI4iP5dSFQI5qf9x8hs4YXvdZ_YSt0quXIc-1733712395-1.0.1.1-3dX4FF_skSGkRtzSX7iWEOn6FsFHmpRyvZuD6HVwpvTUgpxdTioKJ1XIzUqHk0_kXEAJE0Pv6mtkB6G21.NKEQ; _cfuvid=lunNfO6FYG8Bc.nBF_AO.WT3fPIekkpiFtDeaT9tx_A-1733712395504-0.0.1.1-604800000; ASI=01JEMMZM1BH4PACRMBTNF2CBKM",
    "Referer": "https://www.canva.cn/photos/search/%E4%BA%BA%E7%89%A9/",
    "Referrer-Policy": "strict-origin-when-cross-origin"
  },
  "body": null,
  "method": "GET"
});


const referer = "https://www.canva.cn/icons/search/%E4%BA%BA%E7%89%A9/"
//定义cookis和ja3，都是通过验证所需的必要信息
const headers = {
  "accept": "*/*",
  "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  "cache-control": "no-cache",
  "pragma": "no-cache",
  "priority": "u=1, i",
  "sec-ch-ua": "\"Microsoft Edge\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
  "sec-ch-ua-mobile": "?0",
  "sec-ch-ua-platform": "\"Windows\"",
  "sec-ch-ua-platform-version": "\"10.0.0\"",
  "sec-fetch-dest": "empty",
  "sec-fetch-mode": "cors",
  "sec-fetch-site": "same-origin",
  "x-canva-analytics": "AAQAA1dFQgABABowMUpFTU1aTTFCSDRQQUNSTUJUTkYyQ0JLTQ==",
  "x-canva-app": "home",
  "x-canva-authz": "cnvanTFsX5Mdcxxuuc9xeYu-CrHoWh5QfO_Em0TPDvqNJYsNAP2Y2523NN3n-Re0Qefcz6NtkaadTug4_7n6VYBjeO-uDwRqFA9mZlGV-u3le6vo4MVTM96MICI26T_L8yzUmZ89zLCUgWDc2TdaSjbdAbGm3LNEQZ5Jd1v6lMadGgNfZVMPRCB7TXLa_bbLYGrh-5QNMV1Q-sdKrDy3cSNsYq4h9xpjxlsSk06fq-hX6bEu45rsYAssH5g-eGws5xDzca0HAfWy2K0kMXiN01-TSecVZq-wuCRUPikP-h84EPWTYlhEo-Hog5mF6l4bl_LFgDk4DJu2ik8ClzFnfZPd2oyQMFKH1_7LPJqcfQwYepdBujTkleO8oinIN0wLSoro3faqtuKiUG9_T9kbkGcHmd4obT3Kyer3f76HDoT-fLx6QtXr6RjL-qhpGmvei9l5JD-8jydZsvskJisxWFCEfcEKKdTNenSjZvDT90usHRYSqU4yx_PA2Ptx_7UmA20DNexuzO_Xm6daSwpwLT2YnNw-7ZmSYIiEdZyoZEGdkc_uxQqjc46jw-V5iuNNuaYbOBT1L4crDj3V3uUrsnFZiQquDHcMybPBEkicRO9UX31zPDtsuhAFQZQhOT9-nT_3zW3GT9tYyl6rRuK1UJGxjPvHeMn8rpdeEafHt4PxddAcYhxxOZwp-MugJcuakuU7sq_t2Y0fSTy1CFS6db1fIOKPCOyLudF1YMhA2c-D5Do8_ebzTXbX2O3Phl0d1y3fB7dreFjMbIb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51ThIQOsBEWuVwPicw-5tfdUsJi5drtBl5C8oWgLVAuGQftIrGDejTzAL3bkF9ECtcGGIGt-4Dv8QGVAU3SiWEVc6LVQVxYBm9VETPBj4nJohOAnfvHdoCXBSVQF9c_73BkF-zVRteihyJtIIvAria-4nS0qPZ2uRNqcw23YVmlH-p452Rbrzg8PxtogO2-TjGvch43whW3hXrJWmVRe1otWvcJuL6K21c7tAmIPSs79rLEMi279-S8xVO2M1O06VhNutC1juXUuHSFbWjBfQIMJP1QDFsxb-Ch7cV4DKPvubAMfpAaZXUjrHUcEBgsmRc4IfwDFBggcmYtHy574m6JWUPE3qwXdPMpYFpdgINf0pDgg_d9hdtfPoaQxdK4f9nnag-bX2g7ToaaPtsGsURGFH-QlcoJ7B8A9bLn5WQOovFMgKj_lB-xC6g3vPb1lwtKQuRRdp5Ld3hzv0vMAb8423ad8",
  "x-canva-brand": "BAGEapRcxko",
  "x-canva-build-name": "20241203-21",
  "x-canva-build-sha": "d32ea79",
  "x-canva-locale": "zh-CN",
  "x-canva-request": "findmasonrycards",
  "x-canva-user": "UAGDNGYdGao",
  "cookie": "CDI=5bf62074-c1df-4313-9773-bdad79d82313; sensorsdata2015jssdkchannel=%7B%22prop%22%3A%7B%22_sa_channel_landing_url%22%3A%22%22%7D%7D; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%221931e63da3e6f3-0916c5eaca21928-4c657b58-2073600-1931e63da3f1c47%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_utm_source%22%3A%22bing%22%2C%22%24latest_utm_medium%22%3A%22paid%22%2C%22%24latest_utm_campaign%22%3A%22ACQ-poster-make%22%2C%22%24latest_utm_content%22%3A%22sem%22%2C%22%24latest_utm_term%22%3A%22haibaowangzhan%22%7D%2C%22identities%22%3A%22eyIkaWRlbnRpdHlfY29va2llX2lkIjoiMTkyOGYyZGJmYjZiOWUtMGQyZTM2YTQzNDg4ZDA4LTRjNjU3YjU4LTkyMTYwMC0xOTI4ZjJkYmZiNzI1OTkifQ%3D%3D%22%2C%22history_login_id%22%3A%7B%22name%22%3A%22%22%2C%22value%22%3A%22%22%7D%7D; CTC=eyJBIjoxNzMxMzgxNjgzMTQ0LCJCIjoxNzMxMzgxNjgzMTQ0LCJEIjpmYWxzZSwiSSI6Wzg0OTM0NzQzOSwyNjM5OTddLCJKIjpbODQ5MzQ3NDMxLDI2Mzk5N119; Hm_lvt_86fb568838e91564c8549e9ef71194cc=1731381683; gdxidpyhxdE=diU%5CziXouCys2USfah0qu0W2eeI%2B%2F%5CWapPzXh%5Cil%5CABVdMNfrU5gdzmDPvWyvLO8ivRfaGya6gjbc1HLd%2FlXhRfkM2R3s%5C%2FsZt%5CIAEBN%2FDLxPQRkg91GDNoe9CzQKQQXa%2FGcq9CANqyixSvHgGGO1BgL5S9Xb4GSE3E6xDAVfjO5x%5CLO%3A1731382584381; CB=BAGEapRcxko; CAU=eyJBIjoiVUFHRE5HWWRHYW8iLCJCIjoiQkFHRWFwUmN4a28ifQ==; CL=zh-CN; CUL=cnvru9qqBtEPvt7S01pVx9QiWrauI1QGBJroMzJlrdSV9Ilqp3XRtuaXZjizLWyVrWRMSJyD51VwJXJKXYH5K-HZWLkFDI8BOmH4B4dFS761AjqxVElu2994e2944; CS=1; CAZ=cnvanTFsX5Mdcxxuuc9xeYu-CrHoWh5QfO_Em0TPDvqNJYsNAP2Y2523NN3n-Re0Qefcz6NtkaadTug4_7n6VYBjeO-uDwRqFA9mZlGV-u3le6vo4MVTM96MICI26T_L8yzUmZ89zLCUgWDc2TdaSjbdAbGm3LNEQZ5Jd1v6lMadGgNfZVMPRCB7TXLa_bbLYGrh-5QNM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pXm3a_0KjxHFPHCjlKUwprbGdOYtcYAbhetqooG84HKwuJIPGwIV-HEutyYbY9dHJ_E0AMLf-gNjitZIfKGjT5Bf3fa5f37; CUI=vj6xLh83RHYgeO9MSK8SXQMSZw-uz_PadpnrsCY4TPzs6ZNktOb2uTCSLTsPE5yxKxWPpw; __cf_bm=cwNhv2O4aI4iP5dSFQI5qf9x8hs4YXvdZ_YSt0quXIc-1733712395-1.0.1.1-3dX4FF_skSGkRtzSX7iWEOn6FsFHmpRyvZuD6HVwpvTUgpxdTioKJ1XIzUqHk0_kXEAJE0Pv6mtkB6G21.NKEQ; _cfuvid=lunNfO6FYG8Bc.nBF_AO.WT3fPIekkpiFtDeaT9tx_A-1733712395504-0.0.1.1-604800000; ASI=01JEMMZM1BH4PACRMBTNF2CBKM",
  "Referer": "https://www.canva.cn/photos/search/%E4%BA%BA%E7%89%A9/",
  "Referrer-Policy": "strict-origin-when-cross-origin"
}
const ja3 =
  "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,0-5-10-11-13-16-18-23-27-35-43-45-51-17513-65037-65281,4588-29-23-24,0";
const ja3text = "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,5-27-51-23-18-13-17513-45-65037-43-65281-16-35-10-11-0,25497-29-23-24,0";

// 获取tokens
export async function getFollowingPageData(continuationToken: string, limit?: number) {
  let result = { cards: [] as CardItem[], continuationToken: "" };
  await initCycleTLS().then(async (cycleTLS) => {
    sleep(100, 100);
    await cycleTLS
      .get(
        `https://www.canva.cn/_ajax/marketplace2/card/masonry?continuationToken=${encodeURIComponent(
          continuationToken
        )}&limit=${limit}&hasPrimaryAction=false`,
        {
          ja3:ja3text,
          headers: headers,
        }
      )
      .then((res) => {
        if (res.status === 200) {
          return res.body;
        } else {
          console.log(
            `https://www.canva.cn/_ajax/marketplace2/card/masonry?continuationToken=${encodeURIComponent(
              continuationToken
            )}&limit=${limit}&hasPrimaryAction=false`
          );
          throw new Error(String(res.status));
        }
      })
      .then((res) => {
        const index = res.indexOf("{");
        const data: FollowingData = JSON.parse(
          res.substring(index, res.length)
        );
        const continuationToken = data.continuationToken;
        const cards = data.cards.map((item) => {
          return { token: item.N.K.B };
        });
        result = { cards, continuationToken };
      })
      .catch((error) => {
        console.error("Error fetching screen data: ", error);
        throw error;
      });
  });
  return result;
}

export async function getFollowingPageData2(continuationToken: string, limit?: number) {
  let result = { urlList: [] as any[], continuationToken: "", total: 0 };
  await initCycleTLS().then(async (cycleTLS) => {
    sleep(100, 100);
    await cycleTLS
      .get(`https://www.canva.cn/_ajax/marketplace2/card/masonry?continuationToken=${encodeURIComponent(
        continuationToken
      )}&limit=${limit}&hasPrimaryAction=false`, {
        ja3,
        headers: headers,
      })
      .then((res) => {
        if (res.status === 200) {
          return res.body;
        } else {
          console.log(res);
          throw new Error(String(res.status));
        }
      })
      .then((res) => {
        sleep(100, 1000)
        const index = res.indexOf("{");
        const data: TemplateData = JSON.parse(
          res.substring(index, res.length)
        );
        const continuationToken = data.continuationToken;
        const bigUrlList: any[] = data.cards.map((item) => {
          return {
            url: item.L[0].X,
            token: item.I.reference
          }
        })
        const urlList = bigUrlList.map((item) => {
          if (item.url.U) {
            const resUrl = item.url.U.reduce((max: any, current: any) => (current.D > max.D) ? current : max);
            const url = resUrl.B
            const token = item.token
            return { url, token }
          } else {
            const resUrl = item.url.reduce((max: any, current: any) => (current.D > max.D) ? current : max);
            const url = resUrl.B
            const token = item.token
            return { url, token }
          }
        })
        const total = data.totalResults;
        result = { urlList, continuationToken, total };
      })
      .catch((error) => {
        console.error("Error fetching screen data: ", error);
        throw error;
      });
  });
  return result;
}



// 重构，无链式回调，使用async/await
export async function getFollowingPageData3(Token: string, limit: number) {
  let result = { urlList: [] as any[], continuationToken: "", total: 0 };
  try {
    const response = await fetchImageData2(Token, limit);

    if (response.status !== 200) {
      console.error(response);
      throw new Error(String(response.status));
    }
    const res = response.body;
    await sleep(100, 500); // 控制请求节奏
    const index = res.indexOf("{");
    const data: TemplateData = JSON.parse(res.substring(index, res.length));
    const bigUrlList: any[] = data.cards.map((item) => {
      return {
        url: item.L[0].X,
        token: item.I.reference,
      };
    });
    const urlList = bigUrlList.map(item => {
      const urls = item.url.U ? item.url.U : item.url;
      const resUrl = getMaxUrl(urls);
      return { url: resUrl.B, token: item.token };
    });
    const continuationToken = data.continuationToken;
    const total = data.totalResults;

    result = { urlList, continuationToken, total };
  } catch (error) {
    console.error("Error fetching screen data: ", error);
    throw error;
  }

  return result;
}
function getMaxUrl(urls: any[]) {
  return urls.reduce((max, current) =>
    current.D > max.D ? current : max
  );
}

//根据token获取图片url
export async function getImageUrl(token: string) {
  let result = {} as CardItem;
  await initCycleTLS().then(async (cycleTLS) => {
    await cycleTLS
      .get(
        `https://www.canva.cn/_ajax/marketplace2/page/token?token=${encodeURIComponent(token)}`,
        {
          ja3:ja3text,
          headers,
        }
      )
      .then((res) => {
        if (res.status === 200) {
          return res.body;
        } else {
          console.log(
            `https://www.canva.cn/_ajax/marketplace2/page/token?token=${encodeURIComponent(
              token
            )}`
          );
          throw new Error(String(res.status));
        }
      })
      .then((res) => {
        const index = res.indexOf("{");
        const data: ImageDetailData = JSON.parse(
          res.substring(index, res.length)
        );
        result = {
          name: data.page.H1.A,
          url: data.page.H1.D["0"].X["0"].B,
          tag: data.page.DH,
          path: data.page.DI,
          token: token,
          pixel: data.page.H1.D["0"].X["0"].C,
        };
      })
      .catch((err) => {
        console.log(
          `获取url失败 https://www.canva.cn/_ajax/marketplace2/page/token?token=${encodeURIComponent(
            token
          )}`
        );
        throw err;
      });
  });
  return result;
}

export async function getImageUrl2(token: string) {
  let result = {} as CardItem;

  try {
    const response = await fetchImageData(token);

    if (response.status === 200) {
      const res = response.body;
      const index = res.indexOf("{");
      const data: ImageDetailData = JSON.parse(res.substring(index, res.length));

      result = {
        name: data.page.H1.A,
        url: data.page.H1.D["0"].X["0"].B,
        tag: data.page.DH,
        path: data.page.DI,
        token: token,
        pixel: data.page.H1.D["0"].X["0"].C,
      };
    } else {
      console.log(`请求失败: ${response.status}`);
      throw new Error(String(response.status));
    }

  } catch (err) {
    console.log(`获取url失败 https://www.canva.cn/_ajax/marketplace2/page/token?token=${encodeURIComponent(token)}`);
    throw err;
  }

  return result;
}

async function fetchImageData(token: string) {
  const cycleTLS = await initCycleTLS();

  const response = await cycleTLS.get(
    `https://www.canva.cn/_ajax/marketplace2/page/token?token=${encodeURIComponent(token)}`, { ja3, headers, });
  return response;
}
async function fetchImageData2(continuationToken: string, limit: number) {
  const cycleTLS = await initCycleTLS();

  const response = await cycleTLS.get(
    `https://www.canva.cn/_ajax/marketplace2/card/masonry?continuationToken=${encodeURIComponent(
      continuationToken
    )}&limit=${limit}&hasPrimaryAction=false`,
    {
      ja3,
      userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
      headers,
    }
  );

  return response;
}